﻿using System.Linq;
using AmazeUI.db;
using AmazeUI.Imodel;
using WebCommon;

namespace AmazeUI.bll
{
    

    public class XtLogBll : BaseBll
    {
        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="name">错误代码</param>
        /// <param name="ms">错误信息</param> 
        /// <param name="xtLog"></param>
        /// <param name="logTypeId"></param>
        /// <returns></returns>
        public static void SetLog(  IXtLog xtLog, string name, string ms, int logTypeId = 1)
        {
              
            using (var xdb = new XtEntities())
            {
                var xl = new XtLog(xtLog);
                xl.Name = name;
                xl.Details = ms;
                xl.LogTypeId = logTypeId;
                xdb.XtLog.Add(xl);
                xdb.SaveChanges();
            } 
        }
        /// <summary>
        /// 系统用户列表
        /// </summary>
        /// <param name="rows"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public PageListJs<XtLog> GetPage(int rows, int page )
        {
            var xl = this.db.XtLog.OrderByDescending(a=>a.Id);
            return new PageListJs<XtLog>(xl, rows, page); 
        }
        /// <summary>
        /// 系统异常列表
        /// </summary>
        /// <param name="rows"></param>
        /// <param name="page"></param>
        /// <returns></returns>
        public PageListJs<XtError> GetErrorPage(int rows, int page)
        {
            var xl = this.db.XtError.OrderByDescending(a => a.Id);
            return new PageListJs<XtError>(xl, rows, page); 
        }
    }
}